package first.group.ssh.packet;

import first.group.ssh.SSHConsts;
import first.group.ssh.packet.reader.NameListReader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;

public class UserAuthFailurePacket extends Packet {

    public final List<String> continueMethods;
    public final boolean partialSuccess;
    
    public UserAuthFailurePacket(List<String> continueMethods, boolean partialSuccess) {
        super(SSHConsts.SSH_MSG_USERAUTH_FAILURE);
        this.continueMethods = continueMethods;
        this.partialSuccess = partialSuccess;
    }

    public static PacketParser<UserAuthFailurePacket> PARSER = new Parser();

    private static class Parser extends PacketParser<UserAuthFailurePacket> {

        @Override
        public UserAuthFailurePacket parse(ByteBuffer buffer) throws IOException {
            var methods = NameListReader.readNameList(buffer);
            if (methods == null) {
                return null;
            }
            if (!bufferRemains(buffer, 1)) {
                return null;
            }
            var success = buffer.get() != 0;
            return new UserAuthFailurePacket(methods, success);
        }
    }

    @Override
    public void write(ByteBuffer buffer) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
